<?php

$sign = $_GET['sign'];

if($sign && $sign == strtoupper(md5($_SERVER['SERVER_NAME']))){
    $root_dir = realpath(dirname(__FILE__));
    include_once($root_dir."/config/config.php");
    define('APP_DIR',ROOT_DIR."/app/");
    include_once(APP_DIR."/base/defined.php");
    
    require(ROOT_DIR.'/app/base/kernel.php');
    if(!kernel::register_autoload()){
        require(APP_DIR.'/base/autoload.php');
    }
    cachemgr::init(false);
    kernel::single('base_shell_webproxy')->exec_command('cacheclean');
    kernel::single('base_shell_webproxy')->exec_command('kvstorerecovery');
    kernel::single('base_shell_webproxy')->exec_command("update --ignore-download");
    
    $db = kernel::database();
    //清除发货单模板，重新加入新模板
    $db->exec("DELETE FROM sdb_ome_print_tmpl");
    $dlytpl = array('EMS.dtp','POST.dtp','SF1.dtp','SF2.dtp','STO.dtp','TTKDEX.dtp','YTO.dtp','YUNDA.dtp','ZJS1.dtp','ZJS2.dtp','ZTO1.dtp','ZTO2.dtp');
    foreach($dlytpl as $v){
        _default_dlytpl($v);
    }
    
    kernel::single('base_certificate')->register();
}

function _default_dlytpl($dtp){
    $file['tmp_name'] = ROOT_DIR."/app/ome/initial/dlytpl/".$dtp;
    $file['name'] = $dtp;
    $result = kernel::single("ome_print_tmpl")->upload_tmpl($file);
}